#ifndef _CALLEXPRESSION_HPP
#define _CALLEXPRESSION_HPP

#include <string>
#include "Expression.hpp"
#include "Token.hpp"
#include <vector>


namespace ast {

	class CallExpression : public Expression {

	public:
		CallExpression(TOKEN token) {
			_token = token;
		}

		virtual void ExpressionNode() override {}

		virtual string tokenLiteral() override {
			return _token._literal;
		}

		//run()
		//run(1+1,10,test())
		virtual string String() override {
			string out;
			out.append(_name->String());
			out.append(_token._literal);
			auto paramsLen = _params.size();
			if (paramsLen > 0) {
				int index = 1;
				for (auto itr : _params) {
					if (index == paramsLen) {
						out.append(itr->String());
					}
					else {
						out.append(itr->String() + ", ");
					}
					index++;
				}
			}
			out.append(")");
			return out;
		}

		virtual ~CallExpression() {
			if (_name != nullptr) {
				delete _name;
				_name = nullptr;
			}
			if (_params.size() > 0) {
				for (auto itr : _params) {
					if (itr != nullptr) {
						delete itr;
						itr = nullptr;
					}
				}
				_params.clear();
			}
		}

	public:
		TOKEN _token;
		Expression* _name{ nullptr };
		std::vector<Expression*> _params;
	};
}

#endif // !_CALLEXPRESSION_HPP
